package com.example.login.Controller.SysUserController;

import com.example.login.DO.SysUser;
import com.example.login.Service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Controller

public class UserController {
    @Resource
    private UserService UserService;
    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session) {
        System.out.println(username);
        System.out.println(password);
        SysUser loginUser = UserService.login(username,password);
        session.setAttribute("teacherid",username);
        if(loginUser!=null){
            return  "index";
        }
        else {
            return "/begin";
        }
    }
    @RequestMapping("/resigened")
    public String adduser(String userid,long poseid,String username,String password,String usertype,String email,
                          String phonenumber,String sex,String status){
        UserService.addBy(userid,poseid,username,password,usertype,email,phonenumber,sex,status);
        return "index";
    }
    @RequestMapping("/mylist")
    public String mylist(HttpSession session, Model model){
        String teacherid = String.valueOf(session.getAttribute("teacherid"));
        ArrayList<SysUser> mylist = new ArrayList<>();
        SysUser sysUser = UserService.findBy(teacherid);
        mylist.add(sysUser);
        model.addAttribute("mylist",mylist);
        return "mylist";
    }
    @RequestMapping("/updatepassword")
    public String updatepassword(){
        return "updatepassword";
    }
    @RequestMapping("/updatepassword1")
    public String updatepassword1(String password,HttpSession session){
        String teacherid = String.valueOf(session.getAttribute("teacherid"));
        UserService.updatepassword(teacherid,password);
        return "index";
    }
}
